if(@ARGV != 3)
{
	die "perl  perl_split_vcf_maternal_paternal.pl <INVCF> <MATERNAL VCF> <PATERNALVCF>\n";
}
$INVCF=$ARGV[0];
$OUTVCF_M=$ARGV[1];
$OUTVCF_P=$ARGV[2];
chomp($INVCF);
chomp($OUTVCF_M);
chomp($OUTVCF_P);
open(BUFF,$INVCF) or die "no file found $INVCF\n";
open(MATERNAL,">$OUTVCF_M") or die "not able to write the file $OUTVCF_M\n";
open(PATERNAL,">$OUTVCF_P") or die "not able to write the file $OUTPUT_P\n";
while(<BUFF>)
{
	chomp($_);
	if($_ =~ m/^#/)
	{
		print MATERNAL $_."\n";
		print PATERNAL $_."\n";
	}
	else
	{
		@array=split("\t",$_);
		if($array[4] =~ m/DUP/)
		{
			$event=pop(@array);
			@events=split(':',$event);
			#die "@events\n";
			$_=join("\t",@array);		
			print MATERNAL $_."\t";
			print PATERNAL $_."\t";
			for($i=0;$i<@events;$i++)
			{
				if($i!=0)
				{
					print PATERNAL ":";
					print MATERNAL ":";
				}
				$temp=$events[$i];
				$temp=~ s/^\w+\|//g;
				print PATERNAL "$temp";	
				$temp=$events[$i];
				$temp=~ s/\|\w+$//g;
				print MATERNAL "$temp";
			}
			print PATERNAL "\n";
			print MATERNAL "\n";
		}
		else
		{
			$event=pop(@array);
			@events=split(':',$event);
			$_=join("\t",@array);
			print MATERNAL $_."\t";
			print PATERNAL $_."\t";
			for($i=0;$i<@events-1;$i++)
            {
				$temp=$events[$i];
				$temp=~ s/^\w+\|//g;
				print PATERNAL "$temp";
				if($temp > 0)
				{
					print PATERNAL ":1";
				}
				else
				{
					print PATERNAL ":0";
				}		
				$temp=$events[$i];
				$temp=~ s/\|\w+$//g;
				print MATERNAL "$temp";
				if($temp > 0)
				{
					print MATERNAL ":1";
				}
				else
				{
					 print MATERNAL ":0";
				}
            }
			print PATERNAL "\n";
            print MATERNAL "\n";
		}
	}
}
close(BUFF);
close(MATERNAL);
close(PATERNAL);
